<template>
  <div class="out">
    <el-tabs
      type="border-card"
      style=" background-color:rgba(250,250,250,0.5);"
    >
      <el-tab-pane label="众筹" class="text">
        <el-card
          class="box-card"
          :style="bacc()"
          v-for="(item, o) in data1.slice(
            (currentPage - 1) * pagesize,
            currentPage * pagesize
          )"
          :key="o"
        >
          <div class="content">
            <h4>{{ item.cfName }}</h4>
            <a @click="routerTo('/dream', item.cfId)">详情</a>
            <h6>{{ item.cfDeadline }}</h6>
            <p>{{ item.cfIntroduce }}</p>
          </div>
        </el-card>
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage"
            :page-size="pagesize"
            layout="prev, pager, next, jumper"
            :total="pagetotal"
            background
            hide-on-single-page
          >
          </el-pagination>
        </div>
      </el-tab-pane>
      <el-tab-pane label="募捐" class="text">
        <el-card
          class="box-card"
          :style="bacc()"
          v-for="(item, o) in data2.slice(
            (currentPage2 - 1) * pagesize2,
            currentPage2 * pagesize2
          )"
          :key="o"
        >
          <div class="content">
            <h4>捐赠对象：{{ item.nickName }}</h4>
            <a @click="routerTo('/charity/persondonation', item.recipientId)"
              >详情</a
            >
            <p>留言：{{ item.leavingMessage }}</p>
            <p>捐赠金额：{{ item.donationMoney }}</p>
          </div>
        </el-card>
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"
            :current-page.sync="currentPage2"
            :page-size="pagesize2"
            layout="prev, pager, next, jumper"
            :total="pagetotal2"
            background
            hide-on-single-page
          >
          </el-pagination>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {
  getParticipateCrowdFundingListByuserName,
  getMyInfo,
  getByUserName
} from "@/network/profile.js";
export default {
  data() {
    return {
      currentPage: 1,
      pagesize: 20,
      pagetotal: 0,
      currentPage2: 1,
      pagesize2: 20,
      pagetotal2: 0,
      username: "",
      nick: "",
      data1: [
        // {
        //   cfId: "",
        //   cfName: "活动名称",
        //   cfDeadline: "2021-7-1 12:20:32",
        //   cfIntroduce: "参与事迹(捐赠xxx元...)"
        // }
      ],
      data2: [
        // {
        //   recipientId: "捐赠对象id",
        //   leavingMessage: "留言",
        //   donationMoney: "捐赠金额"
        // }
      ]
    };
  },
  created() {
    this.getParticipateCrowdFundingListByuserName();
    this.getMyInfo();
  },
  mounted() {},
  methods: {
    getMyInfo() {
      getMyInfo().then(res => {
        // console.log("username");
        // console.log(res.data.infoVo.username);
        this.username = res.data.infoVo.username;
        getByUserName(this.username).then(res => {
          // console.log("参与募捐：");
          // console.log(res);
          this.data2 = res;
          this.pagetotal2 = this.data2.length;
        });
      });
    },
    getParticipateCrowdFundingListByuserName() {
      getParticipateCrowdFundingListByuserName().then(result => {
        // console.log("参与：");
        // console.log(result);
        this.data1 = result;
        this.pagetotal = this.data1.length;
        for (var i in this.data1) {
          this.data1[i].cfIntroduce = "参与事迹(捐赠xxx元...)";
        }
      });
    },

    routerTo(routerPath, id) {
      console.log(id);
      this.$router.push({
        path: routerPath,
        query: {
          id: id
        }
      });
    },
    handleSizeChange(val) {
      this.pagesize = val;
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      console.log(`当前页: ${val}`);
    },
    handleSizeChange2(val) {
      this.pagesize2 = val;
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange2(val) {
      this.currentPage2 = val;
      console.log(`当前页: ${val}`);
    },
    bacc() {
      let R = Math.floor(Math.random() * 250);
      let G = Math.floor(Math.random() * 250);
      let B = Math.floor(Math.random() * 250);
      return {
        background: "rgba(" + R + "," + G + "," + B + ",0.1)"
      };
    }
  }
};
</script>

<style scoped lang="scss">
/deep/ .el-tabs--border-card > .el-tabs__header {
  background-color: #f1e3df;
}
/deep/ .el-tabs--border-card > .el-tabs__header .el-tabs__item {
  color: rgb(160, 116, 100);
  font-size: 3vh;
}
.out {
  overflow: hidden;
  margin-right: 2vw;
  margin-left: 200px;
}
.content {
  margin: 10px;
  padding-bottom: 10px;
  margin-bottom: 15px;
}
.content a {
  float: right;
  margin-top: -20px;
  text-decoration: underline;
  color: rgb(64, 150, 184);
  font-size: 2.2vh;
  animation: bounceInDown 1s;
  cursor: pointer;
}
.content h4 {
  font-size: 2.8vh;
  animation: bounceInLeft 1s;
}
.content h6 {
  margin: 5px;
  font-size: 1.8vh;
  animation: bounceInLeft 1s;
}
.content p {
  margin-top: 0.5vh;
  font-size: 2.4vh;
  animation: fadeInUpBig 1s;
}
.block {
  margin-top: 10px;
  text-align: center;
}
.box-card {
  width: 320px;
  display: inline-block;
  margin: 10px;
  box-shadow: 5px 5px 10px 3px #aaa;
  border-radius: 10%;
  text-align: left;
}
.text {
  text-align: center;
}
.box-card:hover {
  transform: scale(1.1);
}
</style>
